package com.bzchao.wechat.controller;

import com.bzchao.wechat.wxopen.dto.request.WxParam;
import com.bzchao.wechat.service.WeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/wechat/msg/")
public class WechatMsgController {

    @Autowired
    private WeChatService weChatService;

    /**
     * GET请求响应微信发送的Token验证
     *
     * @param requestParam
     * @return
     */
    @GetMapping(value = "")
    public Object verifyToken(WxParam requestParam) {
        return requestParam.getEchostr();
    }

    /**
     * POST接收微信的事件消息
     */
    @PostMapping(value = "")
    public String handlerMsg(@RequestBody String msgString, WxParam requestParam) {
        return weChatService.getMessageByReqMsg(msgString);
    }
}
